﻿#region

using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

using Pob.GameObjects.PowerUps.Special;
using Pob.ScreenManagement;

#endregion

namespace Pob.GameObjects.PowerUps.General
{
    public enum EnabledPowerUps
    {
        Type1, 

        Type2
    }

    public class PowerUpCreator : GameComponent
    {
        #region Fields

        private readonly List<string> _enabledPowerUps = new List<string>
            {
                "PaddleSizePowerUp"
            };

        private ScreenBase _screen;

        #endregion

        #region Constructors and Destructors

        public PowerUpCreator(Game game, ScreenBase screen)
            : base(game)
        {
            DisplayedPowerUp = null;

            Enabled = false;

            _screen = screen;
        }

        #endregion

        #region Public Properties

        public PowerUp DisplayedPowerUp { get; private set; }

        #endregion

        #region Public Methods and Operators

        public void ClearDisplayedPowerUp()
        {
            DisplayedPowerUp = null;
        }

        public PowerUp CreateRandomPowerUp()
        {
            var random = new Random();

            var powerUpId = random.Next(_enabledPowerUps.Count);

            var settings = SettingsManager.CurrentInstance.Settings;

            var randomPosition = new Vector2(100 + (settings.Width - 200) * (float)random.NextDouble(), 200 + (settings.Height - 400) * (float)random.NextDouble());

            switch (_enabledPowerUps[powerUpId])
            {
                case "PaddleSizePowerUp":

                    Enabled = false;

                    return new PaddleSizePowerUp(Game, "DummyPU", randomPosition, 1, this);
            }

            return null;
        }

        public void Reset()
        {
            if (DisplayedPowerUp != null)
            {
                _screen.RemoveFromMyComponents(DisplayedPowerUp);
                DisplayedPowerUp = null;
            }
        }

        public override void Update(GameTime gameTime)
        {
            if (DisplayedPowerUp == null)
            {
                var random = new Random();

                if (random.Next(1, 601) == 600)
                {
                    DisplayedPowerUp = CreateRandomPowerUp();

                    _screen.AddToMyComponents(DisplayedPowerUp);
                }
            }

            base.Update(gameTime);
        }

        #endregion
    }
}